<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title>租金收取 - ${siteName}</title>
	<meta name="description" content="">
	<meta name="author" content="xuzewei">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" type="text/css" href="css/cloud-admin.css" >
	<link rel="stylesheet" type="text/css" href="css/themes/default.css" id="skin-switcher" >
	<link rel="stylesheet" type="text/css" href="css/responsive.css" >
	<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">
	<!-- JQUERY UI-->
	<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.10.3.custom/css/custom-theme/jquery-ui-1.10.3.custom.min.css" />
	<!-- DATE RANGE PICKER -->
	<link rel="stylesheet" type="text/css" href="js/bootstrap-daterangepicker/daterangepicker-bs3.css" />
	<!-- JQGRID -->
	<link rel="stylesheet" type="text/css" href="js/jqgrid/css/ui.jqgrid.min.css" />
	<!-- HUBSPOT MESSENGER -->
	<link rel="stylesheet" type="text/css" href="js/hubspot-messenger/css/messenger.min.css" />
	<link rel="stylesheet" type="text/css" href="js/hubspot-messenger/css/messenger-theme-flat.min.css" />
	<link rel="stylesheet" type="text/css" href="css/base.css" />
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<style type="text/css">
		.leaseimg1{
			background-color: #ffffff;
			}
		.leaseimg2{
			background-color:#708090;
		}
		.leaseimg3{
			background-color:#00e09e;
		}
		.leaseimg4{
			background-color:#4b5cc4;
		}
	</style>
</head>
<body id="app" ng-app="app" ng-controller="ctrl">
	<!-- HEADER -->
	<jsp:include page="include/header.jsp" />
	<!--/HEADER -->
	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<jsp:include page="include/sidebar.jsp" />
		<!-- /SIDEBAR -->
		<div id="main-content">
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="welcome.jsp">Home</a>
										</li>
									</ul>
									<!-- /BREADCRUMBS -->
									<div class="clearfix">
										<h3 class="content-title pull-left">租金收取</h3>
									</div>
									<div class="description"></div>
								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<div class="box border orange">
							<div class="box-title">
								<h4><i class="fa fa-bars"></i>租金收取</h4>
							</div>
							<div class="box-body big">
								<form role="form">
									<div ng-if="lease.newlyStuats==1">
									<label> 说明：因该用户有新申请工位，需要先缴纳新工位的租金，缴纳的结束时间与您的上一批工位租金缴纳结束时间一致</label>
									<div class="form-group">
									  <label>联系人</label>
									  <input type="text" class="form-control" ng-model="entrepreneur.linkman" readonly='true'>
									</div>
									
									<div class="form-group" ng-if="payment.arrearage!=0">
									  <label>您需缴费{{needPayment.needPayment}}</label>
									</div>
									<div class="form-group" ng-if="payStatus!=0">
									  <label>租金缴纳至</label>
									  <input type="text" class="form-control" value="{{needPayment.endTime1|date:'yyyy-MM-dd'}}"  readonly='true'>
									</div>
									</div>
									<div ng-if="lease.newlyStuats==0">
									 <div class="form-group" ng-if="payStatus!=0">
									  <label>租金有效截止时间</label>
									  <input type="text" id="startTime" class="form-control" value="{{payment.endTime|date:'yyyy-MM-dd'}}"  readonly='true'>
									</div>
									<div class="form-group" ng-if="payment.arrearage!=0">
									  <label>已欠费{{payment.numberMonth}}个月&nbsp;&nbsp;&nbsp;欠费{{payment.arrearage}}</label>
									</div>
									<div class="form-group">
									  <label>联系人</label>
									  <input type="text" class="form-control" ng-model="entrepreneur.linkman" readonly='true'>
									</div>
									</div>
									<div id="select1" class="form-group" >
									  <label ng-if="lease.newlyStuats==0">延期月数({{lease.sumRental}}元/月)</label>
									  <select id="monthNumber" class="form-control" ng-model="monthNumber" ng-change="totalRent1()" >
							    		<option value="1">1个月</option>
							    		<option value="2">2个月</option>
							    		<option value="3">3个月</option>
							    		<option value="4">4个月</option>
							    		<option value="5">5个月</option>
							    		<option value="6">6个月</option>
							    		<option value="7">7个月</option>
							    		<option value="8">8个月</option>
							    		<option value="9">9个月</option>
							    		<option value="10">10个月</option>
							    		<option value="11">11个月</option>
							    		<option value="12">12个月</option>
							    	</select>
									</div>
									<div class="form-group" ng-if="lease.newlyStuats==0">
									  <label>租金缴纳至</label>
									  <input type="text" id="rentalTime" class="form-control"  readonly='true'>
									</div>
									<div class="form-group" ng-if="lease.newlyStuats==0">
									  <label>金额(元)</label>
									  <input type="text" ng-model="totalRent" class="form-control"  readonly='true'>
									</div>
									<button type="submit" class="btn btn-danger" ng-click="submit()">提交</button>
									
								</form>
							</div>
						</div>
						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div><!-- /CONTENT-->
				</div>	
			</div>
		</div>
	</section>
	<!--/PAGE -->
	
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="js/jquery/jquery-2.0.3.min.js"></script>
	<!-- JQUERY UI-->
	<script src="js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- DATE RANGE PICKER -->
	<script src="js/bootstrap-daterangepicker/moment.min.js"></script>
	<script src="js/bootstrap-daterangepicker/daterangepicker.min.js"></script>
	<!-- SLIMSCROLL -->
	<script type="text/javascript" src="js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
	<script type="text/javascript" src="js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript" src="js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
	<!-- JQGRID -->
	<script type="text/javascript" src="js/jqgrid/js/grid.locale-en.min.js"></script>
	<script type="text/javascript" src="js/jqgrid/js/jquery.jqGrid.min.js"></script>
	<!-- COOKIE -->
	<script type="text/javascript" src="js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- HUBSPOT MESSENGER -->
	<script type="text/javascript" src="js/hubspot-messenger/js/messenger.min.js"></script>
	<script type="text/javascript" src="js/hubspot-messenger/js/messenger-theme-flat.js"></script>
	<script type="text/javascript" src="js/hubspot-messenger/js/messenger-theme-future.js"></script>
	<script src="js/script.js"></script>
	<!-- ANGULAR-LIBRARY -->
	<script src="angular-1.5.0-rc.2/angular.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="include/common.js"></script>
	<script>
	var totalRent;
	var monthNumber;
	var endTime2=0;
	var app = angular.module("app", []);
	app.controller('ctrl', function($scope, $http, $httpParamSerializer, $injector, $window) {
		$scope.lease = {
				"id": "${param.id}"
			}
		//提交
		$scope.submit = function() {
			if($scope.lease.newlyStuats==0){
				if (window.confirm('确定要缴费')){
					var reqDate = jQuery.param({
					"leaseId":$scope.lease.id,
					"totalRent":totalRent,
					"rentTime":endTime2,
					"monthNumber":monthNumber,
					});
					var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
				$http.post("api/paymentAction/addPayment", reqDate,reqConfig
						).success(function (data) {
					  isErr(data) ? showErrMsg(data) : showMsg("缴费成功");
					  $window.location.href="lease_pay_list.jsp";
				  });
				}
			}
			if($scope.lease.newlyStuats==1){
				if (window.confirm('确定要缴费')){
					var reqDate = jQuery.param({
					"leaseId":$scope.lease.id,
					"rentTime":$scope.needPayment.endTime1,
					"totalRent":$scope.needPayment.needPayment
				});
					var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
				$http.post("api/paymentAction/addNewlyPayment", reqDate,reqConfig
						).success(function (data) {
					  isErr(data) ? showErrMsg(data) : showMsg("缴费成功");
					  $window.location.href="lease_pay_list.jsp";
				  });
				}
			}
		}; 
		$scope.findPayment=function(){
			var reqDate = jQuery.param({
				"leaseId":$scope.lease.id
			});
			var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
			$http.post("api/paymentAction/findPayment", reqDate,reqConfig
					).success(function (data) {
						if(data.response=="null"){
							alert("请为第一次申请的工位付费");
							$window.location.href="lease_pay_list.jsp";
						}
						$scope.needPayment=data.response;
			  });
		}
		$scope.firstPayment=function(){
			var reqDate = jQuery.param({
				"leaseId":$scope.lease.id
			});
				var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
			$http.post("api/paymentAction/firstPayment", reqDate,reqConfig
					).success(function (data) {
						$scope.payment=data.response;
						$scope.numberMonth1=data.response.numberMonth;
						$scope.rentTime=$scope.payment.endTime;
			  });
		}

		//计算总金额
		$scope.totalRent1 = function(){
			var a=$scope.lease.sumRental;
			var b=$scope.monthNumber;
			var c=$scope.payment.arrearage;
			var d=parseFloat(c);
			$scope.totalRent=(a*b+d).toFixed(2);
			totalRent=(a*b+d).toFixed(2);
			var numMonth=parseInt(b);
			var time=0;
			if(c<=0){
				var endTime=jQuery("#startTime").val();
				time = new Date();
				var spl=endTime.split("-");
				var year1 =spl[0];
				var month1=spl[1];
				var day1=spl[2];
				var time2 = new Date(year1, month1, day1);
				time2.setMonth(time2.getMonth() + (numMonth));
				time.setTime(time2);
			}else{
				time = new Date();
				time.setMonth(time.getMonth()+(numMonth+1));
			}
			 var time1=new Date();
			 time1.setTime(time);
			 var year=time1.getFullYear();
			 var month=time1.getMonth()+"";
			 var day=time1.getDate()+"";
			 if(month.length==1){
				 month="0"+month;
			 }
			 if(day.length==1){
				 day="0"+day;
			 }
			 if(month==00){
					month=12;
					year=year-1;
				}
			 endTime2=year+"-"+month+"-"+day;
			 jQuery("#rentalTime").val(endTime2);
			 monthNumber=b;
		}
		
		//查询lease对象
		$scope.queryLease = function() {
			var reqDate = jQuery.param({
				"leaseId":$scope.lease.id
			});
			var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
			$http.post(
				"api/resourecLease/queryLease", reqDate,reqConfig
			).success(function(data, status) {
				if (isErr(data)) {
					showErrMsg(data);
					return;
				}
				$scope.lease = data.response;
				if(data.response.newlyStuats==1){
					jQuery("#select1").hide();
					$scope.findPayment();
				}
			}).error(function(data, status) {
				showNetworkErrMsg(data, status);
			});
		};
		
		//查询Entrepreneur对象
		$scope.queryEntrepreneur = function() {
			var reqDate = jQuery.param({
				"leaseId":$scope.lease.id
			});
			var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
			$http.post(
				"api/resourecLease/queryEntrepreneur", reqDate,reqConfig
			).success(function(data, status) {
				if (isErr(data)) {
					showErrMsg(data);
					return;
				}
				$scope.entrepreneur = data.response;
			}).error(function(data, status) {
				showNetworkErrMsg(data, status);
			});
		};
		
		$scope.logout = function() {
			logout($window.zone);
		};
	});
	</script>
	<script>
	jQuery(document).ready(function() {
		App.init();
		jQuery('#nav_resource-manage').click();
		setTimeout(function () { 
			var scope = angular.element('#app').scope();
			scope.queryLease();
			scope.queryEntrepreneur();
			scope.firstPayment();
		}, 500);
	});
	</script>
	<!-- /JAVASCRIPTS -->
</body>
</html>